package com.cc.demo.component;

import com.aizuda.snailjob.client.job.core.dto.JobArgs;
import com.aizuda.snailjob.client.job.core.executor.AbstractJobExecutor;
import com.aizuda.snailjob.client.model.ExecuteResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class TestOverlayCanInterrupted extends AbstractJobExecutor {
    @Override
    protected ExecuteResult doJobExecute(JobArgs jobArgs) {
        log.info("{}开始执行任务", Thread.currentThread().getName());
        int i = 1;
        while (!Thread.currentThread().isInterrupted()) {
            log.info("{}执行第{}次", Thread.currentThread().getName(), i);
            try {
                Thread.sleep(60000);
            }catch (InterruptedException e) {
                log.info("{}任务被中断", Thread.currentThread().getName());
                Thread.currentThread().interrupt();;
            }
            i++;
        }
        log.info("{}任务执行完成", Thread.currentThread().getName());
        return ExecuteResult.success();
    }
}
